#ifndef T_AUTOMA_pgmfc_cH
#define T_AUTOMA_pgmfc_cH

struct PGMFC_Native {
	static int init();
	static void release();
	static void test();

	/* Name: 		mfcs_detect
	 *
	 * Description:	detects the connected MFCS and return their serial numbers in the ports
	 * Arguments:
	 * Returns:		ports is the array of all connected MFCS
	 *				C count is the number of available devices
	 */
	static unsigned char mfcs_detect(unsigned short ports[20]);

	/* Name: 		mfcstz_detect
	 *
	 * Description:	detects the connected MFCSTZ
	 * Arguments:
	 * Returns:
	 *				C count is the number of available devices
	 */
	unsigned char mfcstz_detect(unsigned short ports[10]);

	/* Name: 		mfcs_initialization
	 *
	 * Description: initialize USB connection with specific serial number
	 * Arguments:	nPort is the serial number
	 * Returns:	    handle is the identifier of the opened session
	 */
	static unsigned long long mfcs_initialization(unsigned short nPort);

	/* Name: 		mfcstz_initialization
	 *
	 * Description: initialize socket connection with specific port number
	 * Arguments:	nPort is the port number
	 * Returns:	    handle is the identifier of the opened session
	 */
	static  unsigned long long mfcstz_initialization(unsigned short nPort);

	/*Name: 		getChannelsCount
	 *
	 * Description: get the number of independent channels
	 * Arguments:	handle is the identifier of the PGMFC
	 * Returns:		C error is the error code
				channel is the number of channels
	 */
	static  unsigned char mfcs_getchannelscount(unsigned long long handle, unsigned short& channels);

	/* Name: 		mfcs_close
	 *
	 * Description: terminates threads and deallocates memory used by the PGMFC session
	 * Arguments:	handle is the identifier of the PGMFC
	 * Returns:	    C error is the error code
	 */
	static unsigned char mfcs_close(unsigned long long handle);

	/* Name: 		mfcs_set_moduleid
	 *
	 * Description: set module id of the PGMFC device
	 * Arguments:	handle is the identifier of the PGMFC
					id is the id to set
					channel is the channel number (same module id for 1-2, or 3-4)
	 * Returns:	    C error is the error code
	 */
	static  unsigned char mfcs_setmoduleid(unsigned long long handle, unsigned short id, unsigned char channel = 1);

	/* Name: 		mfcs_get_moduleid
	 *
	 * Description: get module id of the PGMFC device
	 * Arguments:	handle is the identifier of the PGMFC
					channel is the channel number (same module id for 1-2, or 3-4)
	 * Returns:	    C error is the error code
					id is the version of the instrument
	 */
	static unsigned char mfcs_getmoduleid(unsigned long long handle, unsigned short& id, unsigned char channel = 1);

	/* Name: 		mfcs_frimwareversion
	 *
	 * Description: gets firmware version of the PGMFC device
	 * Arguments:	handle is the identifier of the PGMFC
	 * Returns:	    C error is the error code
					S version is the version of the instrument
	 */
	static unsigned char mfcs_frimwareversion(unsigned long long handle, char version[30]);

	/* Name: 		mfcs_set_params
	 *
	 * Description: set pressure
	 * Arguments:	handle is the identifier of the MFCS
					channel is the channel number (1-2)
					type is the wave type (1:DC 2:rectangle 3:triangle 4:sine)
					peak is the target pressure for DC, or peak value for other types
					trough is the trough value for other types
					peroid is the period for last 3 types
					duty is the duty for last 3 types  (0.01-99.9)
					runtime is the runtime for target pressure. (s)
					normalopen: true for normal open.
	 * Returns:	    C error is the error code
	 */
	static unsigned char mfcs_set_params(unsigned long long handle, unsigned short channel, unsigned short type,
		float peak, float trough, float peroid, float duty, float runtime, bool normalopen);

	/* Name: 		mfcs_set_params_flowrate
	 *
	 * Description: set liguid flowrate when a flowmeter is connected to the PGMFC device
	 * Arguments:	handle is the identifier of the PGMFC
					channel is the channel number (1-2)
					type is the wave type (1:DC 2:rectangle 3:triangle 4:sine)
					peak is the target pressure for DC, or peak value for other types
					trough is the trough value for other types
					peroid is the period for last 3 types
					duty is the duty for last 3 types  (0.01-99.9)
					runtime is the runtime for target pressure. (s)
					normalopen: true for normal open.
	 * Returns:	    C error is the error code
	 */
	static unsigned char mfcs_set_params_flowrate(unsigned long long handle, unsigned short channel, unsigned short type,
		float peak, float trough, float peroid, float duty, float runtime, bool normalopen);

	/* Name: 		mfcs_monitor_start
	 *
	 * Description: start reading sensor data
	 * Arguments:	handle is the identifier of the MFCS
					span is the interval between two queries. ms
	 * Returns:	    C error is the error code
	 */
	static unsigned char mfcs_monitor_start(unsigned long long handle, unsigned short span = 100);

	/* Name: 		mfcs_monitor_stop
	 *
	 * Description: stop reading sensor data
	 * Arguments:	handle is the identifier of the MFCS
	 * Returns:	    C error is the error code
	 */
	static unsigned char mfcs_monitor_stop(unsigned long long handle);

	/* Name: 		mfcs_purge_on
	 *
	 * Description: start pump
	 * Arguments:	handle is the identifier of the MFCS
	 *				channel is the channel number
	 * Returns:	    C error is the error code
	 */
	static unsigned char mfcs_purge_on(unsigned long long handle, unsigned short channel, bool external = true);

	/* Name: 		mfcs_purge_off
	 *
	 * Description: stop pump
	 * Arguments:	handle is the identifier of the MFCS
	 *				channel is the channel number
	 * Returns:	    C error is the error code
	 */
	static unsigned char mfcs_purge_off(unsigned long long handle, unsigned short channel, bool external = true);

	/* Name: 		mfcs_stopEmergency
	 *
	 * Description: terminates the MFCS from running
	 * Arguments:	handle is the identifier of the MFCS
	 * Returns:	    C error is the error code
	 */
	static unsigned char mfcs_stopEmergency(unsigned long long handle);

	/* Name: 		mfcs_checkAirTempPressure
	 *
	 * Description:
	 * Arguments:	handle is the identifier of the MFCS
	 * Returns:	    C error is the error code
	 */
	unsigned char mfcs_checkAirTempPressure(unsigned long long handle);

	/* Name: 		mfcs_controlValves
	 *
	 * Description: reads the air pressure sensor specification
	 * Arguments:	handle is the identifier of the MFCS
	 *				channel is the channel number
					idValve is the valve id (1-10)
					bOpen, true: on   false: off
	 * Returns:	    C error is the error code
	 */
	unsigned char mfcs_controlValves(unsigned long long handle, unsigned short channel, unsigned short idValve, bool bOpen);

	/* Name: 		mfcs_operateDigitalOutputs
	 *
	 * Description:  operate digital outputs
	 * Arguments:	handle is the identifier of the MFCS
	 *				idPort is output port id (1-6)
					type: 1 for DC, 2 for square
					polarity: 1-high  0 -low
					period: square type use. ms
					pulse: square type use. ms  pulse-Width
	 * Returns:	    C error is the error code
	 */
	unsigned char mfcs_operateDigitalOutputs(unsigned long long handle, unsigned short idPort,
		unsigned short type, unsigned short polarity, unsigned short period, unsigned short pulse);

	/* Name: 		mfcs_queryDigitalIOStates
	 *
	 * Description: query current digital outputs states
	 * Arguments:	handle is the identifier of the MFCS
	 * Returns: 	C error is the error code
					states is a list of all output states. 0-5 for OUT1-6; 6-IN1, 7-IN2
	 */
	unsigned char mfcs_queryDigitalIOStates(unsigned long long handle, unsigned short states[8]);

	/* Name: 		mfcs_checkFlowmeter
	 *
	 * Description: tell controller to check if the flowmeter is connected
	 * Arguments:	handle is the identifier of the MFCS
	 *				channel is the channel number
	 * Returns:	    C error is the error code
	 */
	unsigned char mfcs_checkFlowmeter(unsigned long long handle, unsigned short channel);

	/* Name: 		mfcs_queryFlowmeterInfo
	 *
	 * Description:  tell controller to check if the flowmeter is connected, and wait for the check result.
	 * Arguments:	handle is the identifier of the MFCS
	 *				channel is the channel number
	 * Returns:	    C error is the error code
	 *				connected is whether or not a flowmeter is connected
	 *				smodel is flowmeter model
	 */
	unsigned char mfcs_queryFlowmeterInfo(unsigned long long handle, unsigned short channel, bool& connected, unsigned char smodel[20]);

	/* Name: 		mfcs_queryRotaryAddress
	 *
	 * Description: check if the rotaryvalve is connected
	 * Arguments:	handle is the identifier of the MFCS
	 *				switchType is the rotary switch Type. 1: M-Switch 2: L-Switch
					mountID is the id of switch mounted. 1-2
					connected is whether connected or not
	 * Returns:	    C error is the error code
	 */
	unsigned char mfcs_queryRotaryAddress(unsigned long long handle, unsigned short switchType, unsigned short mountID, bool& connected);

	/* Name: 		mfcs_rotaryReset
	 *
	 * Description: reset to default position
	 * Arguments:	handle is the identifier of the MFCS
	 *				switchType is the rotary switch Type. 1: M-Switch 2: L-Switch
					mountID is the id of switch mounted. 1-2
	 * Returns:	    C error is the error code
	 */
	unsigned char mfcs_rotaryReset(unsigned long long handle, unsigned short switchType, unsigned short mountID);

	/* Name: 		mfcs_queryRotaryCurPos
	 *
	 * Description: query current position
	 * Arguments:	handle is the identifier of the MFCS
	 *				switchType is the rotary switch Type. 1: M-Switch 2: L-Switch
					mountID is the id of switch mounted. 1-2
	 * Returns:	    C error is the error code
	 */
	unsigned char mfcs_queryRotaryCurPos(unsigned long long handle, unsigned short switchType, unsigned short mountID, unsigned short& pos);

	/* Name: 		mfcs_rotarySwitchTo
	 *
	 * Description: switch to X
	 * Arguments:	handle is the identifier of the MFCS
	 *				switchType is the rotary switch Type. 1: M-Switch 2: L-Switch
					mountID is the id of switch mounted. 1-2
					pos is the position to switch to
	 * Returns:	    C error is the error code
	 */
	unsigned char mfcs_rotarySwitchTo(unsigned long long handle, unsigned short switchType, unsigned short mountID, unsigned short portID);

	/* Name: 		mfcs_getCurPressure
	 *
	 * Description:	reads the pressure value of the specified channel
	 * Arguments:	handle is the identifier of the PGMFC
	 *				channel is the channel number
	 * Returns:		C error is the error code
	 *				pressure is the measured pressure in psi
	 *				timeStamp is the counter value of the span(default=100) ms timer
	 */
	unsigned char mfcs_getCurPressure(unsigned long long handle, unsigned short channel, float& pressure, unsigned short& timestamp);

	/* Name: 		mfcs_getCurFlowrate
	 *
	 * Description:	reads the air flowrate value of the specified channel
	 * Arguments:	handle is the identifier of the PGMFC
	 *				channel is the channel number
	 * Returns:		C error is the error code
	 *				flowrate is the measured flowrate in sccm
	 *				timeStamp is the counter value of the span(default=100) ms timer
	 */
	unsigned char mfcs_getCurFlowrate(unsigned long long handle, unsigned short channel, float& flowrate, unsigned short& timestamp);

	/* Name: 		mfcs_getCurFlowrate_Liquid
	 *
	 * Description:	reads the liquid flowrate value of the specified channel when a flowmeter is connected.
	 * Arguments:	handle is the identifier of the PGMFC
	 *				channel is the channel number
	 * Returns:		C error is the error code
	 *				flowrate is the measured flowrate
	 *				timeStamp is the counter value of the span(default=100) ms timer
	 */
	unsigned char mfcs_getCurFlowrate_Liquid(unsigned long long handle, unsigned short channel, float& flowrate, unsigned short& timestamp);

	/* Name: 		mfcs_getCurFlowtotalizer
	 *
	 * Description:	reads the liquid flow totalizer value of the specified channel when a flowmeter is connected.
	 * Arguments:	handle is the identifier of the PGMFC
	 *				channel is the channel number
	 * Returns:		C error is the error code
	 *				flowtotalizer is the measured flowtotalizer since pump started
	 *				timeStamp is the counter value of the span(default=100) ms timer
	 */
	unsigned char mfcs_getCurFlowtotalizer(unsigned long long handle, unsigned short channel, float& flowtotalizer, unsigned short& timestamp);

	/* Name: 		mfcs_getGasPathStatus1
		 *
		 * Description:
		 * Arguments:	handle is the identifier of the PGMFC
		 * Returns:		C error is the error code
		 */
	unsigned char mfcs_queryChannelStatus1(unsigned long long handle);

	/* Name: 		mfcs_getGasPathStatus1
	 *
	 * Description:
	 * Arguments:	handle is the identifier of the PGMFC
	 * Returns:		C error is the error code
	 */
	unsigned char mfcs_queryChannelStatus2(unsigned long long handle);

	/* Name: 		mfcs_getCurGasPathInfo
	 *
	 * Description:
	 * Arguments:	handle is the identifier of the MFCS
	 * Returns:	C error is the error code
	 */
	unsigned char mfcs_getCurChannelInfo(unsigned long long handle, int& pumpStatus, int& runTime, int& waveForm, float& maxValue, float& minValue);
};

#endif